home *** CD-ROM | disk | FTP | other *** search
- page 63, 132
- title ASMTST - used to test machine language links to RM/COBOL
- name asmtst
- ;************************************************************************
- ;* ASMTST *
- ;* *
- ;* Program written by: Ryan-McFarland Date: 84.03.28 *
- ;* Updated: 85.04.10 *
- ;* (Safety check added to loop counter CX) *
- ;* Updated: 85.07.31 *
- ;* (Reworked source from CP/M-86 to DOS assembler) *
- ;* *
- ;* Description: Sample program to illustrate machine language *
- ;* linkage to RM/COBOL. *
- ;* The Runtime would be configured to automatically *
- ;* load this module at startup, by setting Link Addr to *
- ;* be equal to the offset of INITIAL. This would also *
- ;* force the Runtime to call the program INITIAL *
- ;* before the RM/COBOL program begins execution. *
- ;* INITIAL will copy the passed command *
- ;* line arguments to a local data space, and its work *
- ;* is finished. The RM/COBOL program, LNKTST, will *
- ;* later call ASMTST and have the saved *
- ;* command line arguments returned to the program *
- ;* LNKTST. *
- ;* Parameters passed to ASMTST: *
- ;* Register BX points to an argument list *
- ;* that has the structure: *
- ;* ES:BX -> DW Byte count of argments following (e.g = 4) *
- ;* DW OFFSET STRING-VALUE *
- ;* DW OFFSET STRING-LENGTH *
- ;* These two variables are in the calling RM/COBOL *
- ;* program. These offsets are relative to the *
- ;* segment register ES. *
- ;* *
- ;* ASMTST will move the string from its local space here to *
- ;* the RM/COBOL variable STRING-VALUE, and the length *
- ;* of this string to STRING-LENGTH. *
- ;* A return value is returned in register AL *
- ;* Zero if all OK, non-zero in case of error. *
- ;************************************************************************
- page
- CODE SEGMENT BYTE PUBLIC 'CODE'
- ASSUME CS:CODE, DS:CODE
- MAIN PROC FAR
- DW ENDCODE ;Length of module.
- DB 7 ;Length of 'INITIAL'
- DB 'INITIAL' ;Program name
- DW INITIAL ;Entry point
- DB 6 ;Length of 'ASMTST'
- DB 'ASMTST' ;Program name
- DW ASMTST ;Entry point
- DB 0 ;End of table
- ;
- ; Sccs information :
- db '@ #( ) (@)#@(#)' ;SCCS id.
- db 'asmtst.asm' ;Program name % M %.
- db ' ver. '
- db '1.3' ;version % I %.
- db ' 85/07/31 ' ;date % E %.
- db '15:27:17' ;time % U %.
- db '>' ;Ending indicator.
- ; Local data area
- ;
- SPACE EQU 020H ;Value of blank space
- STRING dB 20 dup (?) ;20 bytes to save command line arguments.
- LNGTH dB 2 dup (?) ;A word for length of above string.
- ASMTST:
- ;ES:[BX] points to a byte count.
- MOV CL,ES:[BX] ;Check the low order of the byte count.
- CMP CL,4 ;Byte count is 4 for 2 arguments.
- JNZ FAILURE ;Argument count is not 4, calling error.
- ;Following the byte count is an argument list
- MOV DI,ES: 2 [BX] ;DI points to COBOL variable 'STRING-VALUE'
- MOV SI,OFFSET STRING ;String here is the source.
- MOV CX,WORD PTR LNGTH ;And the length thereof.
- CALL CHECKCX ;Force to within range [1,20]
- HERE:
- MOV AL,[SI] ;Source
- MOV ES:[DI],AL ;Destination
- INC SI
- INC DI
- LOOP HERE ;Move string from here to COBOL
- ;address of 'STRING-LENGTH'.
- MOV DI,ES: 4 [BX] ;DI points to COBOL variable
- ;'STRING-LENGTH'
- MOV AX,WORD PTR LNGTH ;Transfer through AX
- XCHG AH,AL ;COMP-1 variables are in straight
- ;byte order
- MOV ES:[DI],AX ;Transfer string length to COBOL.
- XOR AX,AX ;Clear AX for return code.
- RET ;Return far.
- FAILURE:
- OR AX,2 ;Return non-zero error code.
- RET ;And return far.
- page
- SUBS PROC NEAR
- CHECKCX:
- CMP CX,0 ;CX should not be zero or below
- JG PASS1
- MOV CX,1 ;It is less than 1, force to 1
- PASS1:
- CMP CX,20 ;Should not be above 20
- JLE PASS2
- MOV CX,20 ;Force to 20
- PASS2:
- MOV WORD PTR LNGTH,CX ;Update if changed
- RET
- SUBS ENDP
- page
- ;
- ; INITIAL is executed once at startup time.
- ; it simply moves a string to local space.
- ;
- ; Enters with SI pointing to a character string
- ; and AL the length of that string.
- ;
- ; Runtime configuration note: When using MASM and LINK on
- ; this source, INITIAL has offset 0176 hex. This is the
- ; value to be used for Link Addr when configuring
- ; the runtime so that INITIAL will execute before the
- ; RM/COBOL program begins execution
- ;
- INITIAL:
- MOV BYTE PTR LNGTH,AL ;Length of the string
- MOV BYTE PTR LNGTH+1,00 ;High order byte is zero
- MOV DI,OFFSET STRING ;String should be set to
- MOV AL,SPACE ;blanks.
- MOV CX,20 ;Length of string
- BLANKS:
- MOV [DI],AL ;Blank fill
- INC DI
- LOOP BLANKS
- MOV CX,WORD PTR LNGTH ;Make sure that the string length
- CALL CHECKCX ;Is in the range [1,20]
- MOV DI,OFFSET STRING ;Reset DI to start of string
- LOOP1:
- MOV AL,ES:[SI] ;SI points to command line characters
- MOV [DI],AL ;DI points to local string
- INC SI
- INC DI ;Move the string to our local variable space
- LOOP LOOP1
- XOR AL,AL ;AL=0 for all ok signal, no abnormal
- ;exit
- RET ;Return far
- ENDCODE:
- MAIN ENDP
- code ends
- stack segment byte stack 'stack'
- assume ss:stack
- stack ends
- END INITIAL ;Theoretical entry point if this was a normal program
-